<?php
/**
 * 系統名稱: Lotto 系統
 * 檔案說明: 專案管理-修改
 * $Author$
 * $Id$
 *
 */

if (!defined("VirtualHost_lib_include")){
	define("VirtualHost_lib_include", 1);
/**
 * 依網域名稱取得 對應資料
 * @param	strHostName 網域名稱
 * @return	正確傳回 Array
 */
	function getVirtualHostByHostName($strHostName){
		global $_Conn, $$_Conn;
		$strSQL = "select * from `bet_VirtualHost` where HostName = '".$strHostName."'";
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
			$GLOBALS["errormessage"] = "Find VirtualHost Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$arrHost = array();
		if(PMA_mysql_num_rows($RS) == 0)return $arrHost;

		while($Rows = PMA_mysql_fetch_object($RS)){
			$arrHost[$Rows -> ID] = $Rows;
		}
		return $arrHost;
	}

/**
 * 依 ID 取得 對應資料
 * @param	intID 序號
 * @return	正確傳回 Object
 */
	function getVirtualHostByID($intID){
		global $_Conn, $$_Conn;
		$strSQL = "select * from `bet_VirtualHost` where ID = '".$intID."'";
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
			$GLOBALS["errormessage"] = "Find VirtualHost Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		if(PMA_mysql_num_rows($RS) == 0)return false;
		return PMA_mysql_fetch_object($RS);
	}

/**
 * 新增網域總監對照表資料
 * @param	strHostName 網域名稱
 * @param	strDirectID 總監序號
 * @param	strMemo 備註資料
 * @return	正確傳回 int
 */
	function addVirtualHostData($strHostName, $strDirectID, $strMemo){
		global $_ConnMaster;
		$strSQL = "insert into `bet_VirtualHost`(`HostName`, `DirectID`, `Memo`) values('".$strHostName."', '".$strDirectID."', '".$strMemo."')";

		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Add VirtualHost Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		return mysql_insert_id($_ConnMaster);
	}


/**
 * 修改網域總監對照表資料
 * @param	intID 序號
 * @param	strHostName 網域名稱
 * @param	strDirectID 總監序號
 * @param	strMemo 備註資料
 * @return	正確傳回 true
 */
	function setVirtualHostData($intID, $strHostName, $strDirectID, $strMemo){
		global $_ConnMaster;
		$strSQL = "update `bet_VirtualHost` set `HostName` = '".$strHostName."', `DirectID` = '".$strDirectID."', `Memo` = '".$strMemo."' where ID = ".$intID;

		if(!PMA_mysql_query($strSQL, $_ConnMaster)){
			$GLOBALS["errormessage"] = "Add VirtualHost Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($_ConnMaster)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}
		return true;
	}


/**
 * 產生網域總監對應檔
 * @return	正確傳回 true
 */
	function getVirtualHostDataFile(){
		global $_Conn, $$_Conn;
		$strSQL = "select * from `bet_VirtualHost` where 1";
		if(!$RS = @PMA_mysql_query($strSQL, $$_Conn)){
			$GLOBALS["errormessage"] = "Find VirtualHost Data Error!!";
			$GLOBALS["errorhidden"] = "Error: ".PMA_mysql_error($$_Conn)."\nLine:".__LINE__."\nPage:".__FILE__;
			return false;
		}

		$strCon = '<?php'."\n";
		while($Rows = PMA_mysql_fetch_object($RS)){
			$strHost = str_replace(".", "_", $Rows -> HostName);
			$strHost = strtolower($strHost);
			$strCon .= '$_arrGLink["'.$strHost.'"] = array('.$Rows -> DirectID.');'."\n";
		}
		$strCon .= '?>';

		$strFile = __Common_Path."/VirtualHostForDirector.inc.php";
		if(!writeFile($strFile, $strCon, "w"))return false;
		return true;
	}
//-------------------------------------------------------//
//VirtualHost_lib End
}
?>
